ifeq ($(yt_srctree),)
yt_srctree := $(patsubst %/,%,$(dir $(CURDIR)))
yt_srctree := $(patsubst %/,%,$(dir $(yt_srctree)))
yt_srctree := $(patsubst %/,%,$(dir $(yt_srctree)))
endif

BPF_BUILF_CONFIG_FILE ?= $(yt_srctree)/hacks/yt_build_bpf_yocto_v3.mk
include ${BPF_BUILF_CONFIG_FILE}
CFLAGS += $(shell grep -q "define HAVE_ATTR_TEST 1" ${KERNEL_SRC_PATH}/tools/perf/perf-sys.h \
                  && echo "-DHAVE_ATTR_TEST=0")
BPFTOOL := bpftool
BPF_SRCS := 3.bpf.c
BPF_LOADER := loader
# 必须要得加上 -O2 优化等级 
CLANG_BPF_SYS_INCLUDES = $(shell $(CLANG) -v -E - </dev/null 2>&1 | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }')

helloworld.bpf.o:helloworld.bpf.c
	${CLANG} -g -O2 -target bpf -D__TARGET_ARCH_arm64  $(CLANG_BPF_SYS_INCLUDES) -c helloworld.bpf.c
helloworld.skel.h: helloworld.bpf.o
	$(BPFTOOL) gen skeleton helloworld.bpf.o > helloworld.skel.h


${BPF_LOADER}: helloworld.bpf.c helloworld.skel.h
	${CC} $(CFLAGS)  -g -O2 -D__TARGET_ARCH_$(ARCH) ${LOADINCLUDE} $(CLANG_BPF_SYS_INCLUDES) -o ${BPF_LOADER} loader.c ${liba_path}
build: ${BPF_LOADER}

all: clean build push
push:
	adb push ${BPF_LOADER} /data/
	adb shell sync
	adb shell "cd /data && scp ${BPF_LOADER}  root@192.168.100.1:~/"

clean:
	rm -rf *.o helloworld
.DEFAULT_GOAL := all